﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using mal.WP7.Framework.Helpers;
using System.Globalization;

namespace mal.WP7.GoogleAnalytics.Business.GoogleApi
{
    public class FeedRequest
    {
        public string WebSiteId { get; set; }

        public DateTime StartDate { get; set; }

        public DateTime EndDate { get; set; }

        public Metric[] Metrics { get; set; }

        public Dimension Dimension { get; set; }

        private static Metric[] detailMetrics = new Metric[] { 
        Metric.Visits,
        ////Metric.AvgTimeOnSite,
        ////Metric.VisitBounceRate,
        Metric.Visitors,
        Metric.Pageviews,
        ////Metric.PageviewsPerVisit
        };

        #region Dashboard
        public static FeedRequest GetFeedDashboardDay()
        {
            FeedRequest request = new FeedRequest();
            request.StartDate = DateTime.Now.AddDays(-2);
            request.EndDate = DateTime.Now.AddDays(-1);
            request.Metrics = new Metric[1] { Metric.Visits };

            request.Dimension = Dimension.Day;
            return request;
        }

        public static FeedRequest GetFeedDashboardWeek()
        {
            FeedRequest request = new FeedRequest();
            request.EndDate = DateTime.Now.AddDays(-1);

            DateTime firstDayOfCurrentWeek = DateTimeHelper.GetFirstDayOfWeek(request.EndDate, new CultureInfo("en-us"));
            request.StartDate = firstDayOfCurrentWeek.AddDays(-7);

            request.Metrics = new Metric[1] { Metric.Visits };

            request.Dimension = Dimension.Week;
            return request;
        }

        public static FeedRequest GetFeedDashboardMonth()
        {
            FeedRequest request = new FeedRequest();
            request.EndDate = DateTime.Now.AddDays(-1);

            DateTime firstDayOfCurrentMonth = DateTimeHelper.GetFirstDayOfMonth(request.EndDate);
            request.StartDate = DateTimeHelper.GetFirstDayOfMonth(firstDayOfCurrentMonth.AddDays(-1));

            request.Metrics = new Metric[1] { Metric.Visits };

            request.Dimension = Dimension.Month;
            return request;
        }

        public static FeedRequest GetFeedDashboardYear()
        {
            FeedRequest request = new FeedRequest();
            request.EndDate = DateTime.Now.AddDays(-1);

            DateTime firstDayOfCurrentYear = DateTimeHelper.GetFirstDayOfYear(request.EndDate);
            request.StartDate = DateTimeHelper.GetFirstDayOfYear(firstDayOfCurrentYear.AddDays(-1));

            request.Metrics = new Metric[1] { Metric.Visits };

            request.Dimension = Dimension.Year;
            return request;
        }
        #endregion

        #region Detail
        public static FeedRequest GetFeedDays()
        {
            FeedRequest request = new FeedRequest();
            request.StartDate = DateTime.Now.AddDays(-31);
            request.EndDate = DateTime.Now.AddDays(-1);
            request.Metrics = detailMetrics;

            request.Dimension = Dimension.Day;
            return request;
        }

        public static FeedRequest GetFeedWeeks()
        {
            FeedRequest request = new FeedRequest();
            request.EndDate = DateTime.Now.AddDays(-1);

            request.StartDate = DateTime.Now.AddMonths(-6);
            request.StartDate = DateTimeHelper.GetFirstDayOfWeek(request.StartDate, new CultureInfo("en-us"));
            request.Metrics = detailMetrics;

            request.Dimension = Dimension.Week;
            return request;
        }

        public static FeedRequest GetFeedMonths()
        {
            FeedRequest request = new FeedRequest();
            request.EndDate = DateTime.Now.AddDays(-1);

            request.StartDate = DateTime.Now.AddYears(-2);
            request.StartDate = DateTimeHelper.GetFirstDayOfMonth(request.StartDate);

            request.Metrics = detailMetrics;

            request.Dimension = Dimension.Month;
            return request;
        }


        #endregion
    }
}
